import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.1
import org.qtproject.qtquick 1.0

import "../delegate"
import "../common"
import "../page"

BorderImage {
    id: id_messageSent
    width: Math.max(id_txtMessageSent.contentWidth , id_rowNotify.width) + 2 * m_margin
    height: id_txtMessageSent.contentHeight + id_waitingMessageSend.height + m_margin * 2

    property int m_maxWidth: id_conversationDelegate.width - id_timeSent.width - id_errorMessage.width - 2 * m_margin;
    property bool m_visibleTime: false;
    property int m_margin: 30 * m_ratio

    property bool m_deviveredMessage: deliveredMsg

    property string soruce_image: "qrc:/images/resources/box-chat/box_chat_self@2x.png"
    property string soruce_imageCombine: "qrc:/images/resources/box-chat/box_chat_self@2x_combine.png"

    border {
        left: 5 * m_ratio;
        top: 5 * m_ratio;
        right: 2 * m_margin;
        bottom: 5 * m_ratio;
    }

    source: combinedMessage === true ? soruce_image : soruce_imageCombine

    Column {
        id: id_columnSentMsg
        spacing: 10 * m_ratio

        x: m_margin * 0.5

        anchors.verticalCenter: parent.verticalCenter

        Text {
            id: id_txtMessageSent
            width: m_maxWidth

            text: txtMessage

            color: "#14aaff"
            font.family: "Arial"
            wrapMode: Text.WordWrap
            font.pixelSize: 20 * m_ratio;
        }

        Row {
            id: id_rowNotify

            x: id_columnSentMsg.x + m_margin * 0.5

            width: m_deviveredMessage === true ? id_deliveredMessage.width : id_waitingMessageSend.width

            WaitingMessage {
                id: id_waitingMessageSend
                width: 10 * m_ratio
                height: 10 * m_ratio
                color: "transparent"

                visible: !m_deviveredMessage

            }
            DeliveredMessage {
                id: id_deliveredMessage
                width: 10 * m_ratio
                height: 10 * m_ratio
                color: "transparent"

                visible: m_deviveredMessage
            }
        }
    }

    /// chinh lai cho nay sau

    //    MouseArea {
    //        anchors.fill: id_messageSent
    //        onClicked: {
    //            if (m_visibleTime === false) {
    //                m_visibleTime = true;
    //                id_messageSent.height = id_txtMessageSent.contentHeight  + id_time.contentHeight + m_margin * m_ratio
    //            } else {
    //                m_visibleTime = false;
    //                id_messageSent.height = id_txtMessageSent.contentHeight + m_margin * m_ratio
    //            }
    //        }
    //    }

}
